//
//  VisitorView.swift
//  Weibo(Swift)
//
//  Created by 阳 on 16/7/9.
//  Copyright © 2016年 阳. All rights reserved.
//

import UIKit
import SnapKit
protocol VisitorViewDelegate : NSObjectProtocol
{
    func signUp()
    func login()
}
class VisitorView: UIView {

    weak var delegate : VisitorViewDelegate?
    /// 主题图片
    lazy var iconView : UIImageView = UIImageView(imageName: "visitordiscover_feed_image_house")
    
    /// 旋转图片
    lazy var circleView : UIImageView = UIImageView(imageName: "visitordiscover_feed_image_smallicon")
    
    /// 遮罩图片
    lazy var maskImageView : UIImageView = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
    
    /// 提示语
    lazy var tipLabel : UILabel = UILabel(text: "亲爱的用户您还未登录,请登录后查看更多", textAlignment: .Center)
    
    /// 注册按钮
    lazy var signUpButton : UIButton = UIButton(backgroundImage: "common_button_white_disable", title: "注册", titleColor: ThemeColor, fontSize: 14, target: self, action: "didClickSignUp")
    
    /// 登录按钮
    lazy var loginButton : UIButton = UIButton(backgroundImage: "common_button_white_disable", title: "登录", titleColor: ThemeColor, fontSize: 14, target: self, action: "didClickLogin")
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor(red: 236/255.0, green: 236/255.0, blue: 236/255.0, alpha: 1)
    
        setUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

// MARK: - 点击事件
extension VisitorView
{
    func didClickSignUp()
    {
        self.delegate?.signUp()
    }
    func didClickLogin()
    {
        self.delegate?.login()
    }
}
// MARK: - 布局子控件
extension VisitorView
{
    func setUI()
    {
        
        addSubview(iconView)
        addSubview(circleView)
        addSubview(maskImageView)
        addSubview(tipLabel)
        addSubview(signUpButton)
        addSubview(loginButton)
      
        self.iconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self)
            make.centerY.equalTo(self).offset(-100)
            
        }
        self.circleView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(iconView)
        }
        self.maskImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(circleView)
            make.top.equalTo(circleView.snp_bottom).offset(-140)
            
        }
        
        self.tipLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView)
            make.top.equalTo(maskImageView.snp_bottom)
        }
        
        self.signUpButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.center.x).offset(-50)
            make.top.equalTo(tipLabel.snp_bottom).offset(30)
            make.width.equalTo(70)
            make.height.equalTo(22)
        }
        
        self.loginButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.center.x).offset(50)
            make.top.equalTo(tipLabel.snp_bottom).offset(30)
            make.width.equalTo(70)
            make.height.equalTo(22)
            
        }
        circleViewAnimation()
       
    }
    func circleViewAnimation()
    {
        let animation : CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation")
        animation.fromValue = 0
        animation.toValue = 2 * M_PI
        animation.duration = 20
        circleView.layer.addAnimation(animation, forKey: nil)
    }
}